﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TSVA06 
    { 
      
        #region ==VART===========
        public static readonly DependencyProperty VARTProperty = DependencyProperty.Register("VART",
            typeof(string), typeof(TSVA06),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVARTChanged));
        public string VART
        {
            get
            {
                return (string)GetValue(VARTProperty);
            }
            set
            {
                SetValue(VARTProperty, value);
                Refresh();
            }
        }
        private static void OnVARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TSVA06;
            if (src != null)
            {
                src.VART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==PDART===========
        public static readonly DependencyProperty PDARTProperty = DependencyProperty.Register("PDART",
            typeof(string), typeof(TSVA06),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPDARTChanged));
        public string PDART
        {
            get
            {
                return (string)GetValue(PDARTProperty);
            }
            set
            {
                SetValue(PDARTProperty, value);
            }
        }
        private static void OnPDARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TSVA06;
            if (src != null)
            {
                src.PDART = (string)e.NewValue;
            }
        }
        #endregion 
         
        public TSVA06()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VVAART();
            DataContext = MV;
            InitializeComponent();
        } 
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);           
            if (dwMaster == null)
            {
                KEY = "";
                VART = "";
                ART = "";
                PDART = "";
            }
            else
            {  
                KEY = dwMaster["VAAKOLL"].ToString() + dwMaster["VAAART"].ToString();
                VART = dwMaster["VAAKOLL"].ToString() + dwMaster["VAAART"].ToString();
                ART = dwMaster["VAAART"].ToString();
                PDART = dwMaster["VAADART"].ToString() + dwMaster["VAADVAR"].ToString();
            }
        } 
        public void Refresh()
        {
            if (TBMain == null)
                return;
            Locate("VAAART",VART.Trim()); 
        }        
        public override void OnEXAUFChg(string value)
        {
            if (value.ToString().Length == 0)
            {
                return;
            }
            if (ARTST == "")
                ARTST = "F";
            KOLL = value;
            dwData = TBMain.NewRow();
            dwData["VAAMANDANT"] = app.Mandant;
            dwData["VAAKOLL"] = value;
            dwData["VAAARTST"] = ARTST;
            SResult = TMV.QVA_1(dwData);
            MergeData(SResult, false);
            cVA06.Text = "";
            base.OnEXAUFChg(value);
        }
        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            if (IsManage)
            {
                OnEXAUFChg(KOLL);
            } 
            base.ManageCommand(sender, e);
        }

    }
}
